package com.codingday.app;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;


public class MyLocationManager {
	double latitude;
	double longitude;
	
	Criteria cta;
	LocationManager locationManager;
	String provider;
	static MyLocationManager instance=null;
	Context context;
	
	private void checkProvider() {
	       locationManager =(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
	       cta=new Criteria();
	       cta.setAccuracy(Criteria.ACCURACY_FINE);
	       cta.setPowerRequirement(Criteria.POWER_HIGH);
	       cta.setAltitudeRequired(false);
	       cta.setSpeedRequired(false);
	       cta.setCostAllowed(false);
	       provider = locationManager.getBestProvider(cta, true);
	}
	
	private MyLocationManager(Context context){
		latitude = 0.0;
		longitude = 0.0;
		this.context = context;
		checkProvider();
	}
	
	public float getDistanceTo(double todoLatitude, double todoLongitude){
		float[] results = new float[10];
		Location.distanceBetween(todoLatitude, todoLongitude, latitude, longitude, results);
		return results[0];
	}
	
	public static MyLocationManager getInstance(Context context){
		if(instance == null){
			instance = new MyLocationManager(context);
		}
		return instance;
	}
	
	/*
	public void setLatitude(double latitude){
		this.latitude = latitude;
	}
	
	public void setLongitude(double longitude){
		this.longitude = longitude;
	}
	*/
	
	public void setLocation(double latitude, double longitude){
		this.longitude = longitude;
		this.latitude = latitude;
		//TODOMapView.getInstance().initMapView();
	}
	
	public double getLatitude(){
		return this.latitude;
	}
	public double getLongitude(){
		return this.longitude;
	}
	

	
}
